﻿var pointList = [
				[150, 359],
				[368, 210],
				[335, 362],
				[189, 216],
				[208, 376],
				[413, 254],
				[273, 193],
				[214, 288],
				[404, 327],
				[318, 255],
				[268, 379],
				[128, 268],
				[265, 294],
				[227, 240],
				[361, 284],
				[179, 324],
				[270, 236],
				[309, 310],
				[385, 363],
				[230, 330],
				[300, 366],
				[354, 323],
				[171, 260],
				[320, 190]
			];
			var imgList = [];
			var index = 0;
			var hand;
			var handList = [];
			var angle = 0;
			var wan;
			var isPlay=false;
			var handPos=[80,680];
			var resultList=[];
			$(document).ready(function() {
				for (var i = 0; i < 6; i++) {
					var img = $.dice();
					img.move(pointList[i][0], pointList[i][1]+500);
					imgList.push(img);
				}
				handList.push($.pq_createImg("img/hand0.png", ".hand", "absolute", "hidden"));
				handList.push($.pq_createImg("img/hand1.png", ".hand", "absolute"));
				hand = $("#hand");
			});
			$(document).mousemove(function(e) {
				if(isPlay)return;
				$(hand).css("left", e.pageX - 120);
				$(hand).css("top", e.pageY - 120);
			});
			$(document).click(function(e) {
				var can=getResult();
				if(!can)return;
				if(isPlay)return;
				for (var i = 0; i < 6; i++){
					//imgList[i].play(200, 400);
				}
				setTimeout(showSZ, 500);
				setTimeout(showHand, 1000);
				setTimeout(showResult, 1500);
				isPlay=true;
				$(hand).frameAnimate({speed:30}, function() {
					var l=parseInt($(hand).css("left"));
					var t=parseInt($(hand).css("top"));
					$(hand).css("left", l+(handPos[0]-l)/3);
					$(hand).css("top", t+(handPos[1]-t)/3);
				})
			});
			function showSZ(){
				$(handList[0]).css("visibility", "initial");
				$(handList[1]).css("visibility", "hidden");
				//$("#sz").hide();
				for (var i = 0; i < 6; i++){
					imgList[i].move(300,800);
				}
				handPos=[180,680];
			}
			function showHand() {
				$(handList[0]).css("visibility", "hidden");
				$(handList[1]).css("visibility", "initial");
				//$("#sz").show();
				$(hand).stopFrameAnimate();
				for (var i = 0; i < 6; i++){
					imgList[i].play(200, 800);
				}
			}
			function showResult(){
				var mn=pointList.length-6;
				var n=parseInt(Math.random()*mn);
				for (var i = n; i < n+6; i++){
					imgList[i-n].stop(resultList[i-n],pointList[i][0], pointList[i][1]+500);
				}
				isPlay=false;
				setTimeout(showWin,2000);
			}
			//这里调用后台获得结果
			function getResult(){
				resultList=[1,2,3,4,5,0];
				return true;//如果次数不够或其它原因无法抽奖请返回false
			}
			//这里显示中奖提示
			function showWin(){
				alert("恭喜您博中状元无用奖！");
			}
